package com.youlu.campus.web.config.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author : [dengbo]
 * @className : VotePvAspct
 * @description : [投票pv统计]
 * @createTime : [2022/7/7 16:41]
 */
@Component
@Aspect
@Slf4j
public class VotePvAspect {

    @Pointcut("(execution(public * com.youlu.campus.web.vote.*.*(..)) && @annotation(votePvStatistics))")
    public void votePvSt(VotePvStatistics votePvStatistics) {
    }


    @After("@annotation(votePvStatistics) || @within(votePvStatistics)")
    public void doAfterAdvice(JoinPoint joinPoint, VotePvStatistics votePvStatistics) {
        // 判断是否需要校验
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        log.info("After，param:{},e",votePvStatistics);
    }

    @AfterThrowing(pointcut = "votePvSt(votePvStatistics)", throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint, VotePvStatistics votePvStatistics, Throwable e) {
        log.info("AfterThrowing，param:{},e",votePvStatistics,e);
    }

}
